package fy.bean;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import fy.util.DBUtil;
public class CourtIntroduce {
	private int id;
	private static String category;
	private String title;
	private String content;
	private int homepage;
	private String author;
	private Date time;
	private String picturetitle;
	private String picture;
	private String source;
	private int puton;
	public int getPuton() {
		return puton;
	}
	public void setPuton(int puton) {
		this.puton = puton;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}

	PreparedStatement statement=null;
	ResultSet rs = null;
	Connection connection = null;
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getHomepage() {
		return homepage;
	}
	public void setHomepage(int homepage) {
		this.homepage = homepage;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}

	public String getPicturetitle() {
		return picturetitle;
	}
	
	public void setPicturetitle(String picturetitle) {
		this.picturetitle = picturetitle;
	}
	
	//模糊查询
	public List<CourtIntroduce> Proselect(String lbString,String tilString,Page page) {
		  List<CourtIntroduce> list =new ArrayList<CourtIntroduce>();
		  DBUtil dbUtil = new DBUtil();
		  connection = dbUtil.geConnection();
		  //String sql = "select * from news";
		  String sql ="select * from courtintroduce where category =? and concat(id,title,content,category,author,source,time,picture,picturetitle,puton) like ? order by time desc limit ?,?" ;
		  connection = dbUtil.geConnection();
		  try {
		   statement = connection.prepareStatement(sql);
		   statement.setString(1, lbString);
		     statement.setString(2,"%" + tilString + "%");
		     statement.setInt(3, page.getBeginIndex());
		     statement.setInt(4, page.getEveryPage());
		   rs = statement.executeQuery();
		   while(rs.next()) {
			CourtIntroduce courtIntroduce = new CourtIntroduce();
			courtIntroduce.setId(rs.getInt("id"));
			courtIntroduce.setTitle(rs.getString("title"));
			courtIntroduce.setContent(rs.getString("content"));
			courtIntroduce.setCategory(rs.getString("category"));
			courtIntroduce.setAuthor(rs.getString("author"));
			courtIntroduce.setSource(rs.getString("source"));
			courtIntroduce.setTime(rs.getDate("time"));
			courtIntroduce.setPicture(rs.getString("picture"));
			courtIntroduce.setPicturetitle(rs.getString("picturetitle"));
			courtIntroduce.setPuton(rs.getInt("puton"));
		    list.add(courtIntroduce);
		   }
		   
		  } catch (SQLException e) {
		   e.printStackTrace();
		  }finally {
		   if (rs != null) {
		    try {
		     rs.close();
		    } catch (SQLException e) {
		     e.printStackTrace();
		    }
		   }
		   if (statement != null) {
		    try {
		     statement.close();
		    } catch (SQLException e) {
		     e.printStackTrace();
		    }
		   }
		   if(connection != null) {
		    try {
		     connection.close();
		    } catch (SQLException e) {
		     e.printStackTrace();
		    }
		   }
		   dbUtil.close();
		  }
		  return list;
		  
		 }
	private void setString(int i, String string) {
		// TODO Auto-generated method stub
		
	}
public boolean doUpdata(String category,String title,String content,String picture,String author,String source,String txtDate,int puton,int id) {
		boolean updata = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		//String sql = "select password from admin where username = " + username + "'";
		String sql = "update courtintroduce set category =?,title =?,content =?,picture =?,author =?,source=?,time=?,puton=?  where id =?";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			statement.setString(2, title);
			statement.setString(3, content);
			statement.setString(4, picture);
			statement.setString(5, author);
			statement.setString(6, source);
			statement.setString(7, txtDate);
			statement.setInt(8, puton);
			//statement.setDate(8, (java.sql.Date) date1);
			statement.setInt(9, id);
			System.out.println(updata);
			int i = statement.executeUpdate();
			if (i>0) {
				updata = true;
			}
				
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return updata;
		
	}

	/*
	 * public boolean Updata(String category,String title,String content,int
	 * homepage,String picture,String author, String source,String txtDate,int id) {
	 * System.out.print("1"+category+title+content+author+source+id); boolean updata
	 * = false; DBUtil dbUtil = new DBUtil(); connection = dbUtil.geConnection();
	 * //String sql = "select password from admin where username = " + username +
	 * "'"; String sql =
	 * "update courtintroduce set category =?,title =?,content=?,homepage=?,source=?,picture=?,author =?,source=?,txtDate=?,where id =?"
	 * ;
	 * 
	 * try { PreparedStatement statement = connection.prepareStatement(sql);
	 * statement.setString(1, category); statement.setString(2, title);
	 * statement.setString(3, content); statement.setInt(4, homepage);
	 * statement.setString(5, picture); statement.setString(6, author);
	 * statement.setString(7, source); statement.setString(8, txtDate);
	 * statement.setInt(9, id); System.out.println(updata); int i =
	 * statement.executeUpdate(); if (i>0) { updata = true; }
	 * 
	 * } catch (SQLException e) { e.printStackTrace(); }finally { if (rs != null) {
	 * try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if
	 * (statement != null) { try { statement.close(); } catch (SQLException e) {
	 * e.printStackTrace(); } } if(connection != null) { try { connection.close(); }
	 * catch (SQLException e) { e.printStackTrace(); } } dbUtil.close(); } return
	 * updata;
	 * 
	 * }
	 */
//增加内容
	public boolean doAdd(String category,String title,String content,Integer homepage,String picture,String author,String source,String txtDate,Integer puton) {
		boolean add = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		//String sql = "select password from admin where username = " + username + "'";
		String sql = "insert into courtintroduce(category,title,content,homepage,picture,author,source,time,puton) values(?,?,?,?,?,?,?,?,?)";
		
	  try {		
		  PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			statement.setString(2, title);
			statement.setString(3, content);
			statement.setInt(4, homepage);
			statement.setString(5, picture);
			statement.setString(6, author);
			statement.setString(7, source);
			statement.setString(8, txtDate);
			statement.setInt(9, puton);
			System.out.println(add);
			int i = statement.executeUpdate();
			if (i>0) {
				add = true;
			}
				
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return add;
	}

	/*
	 * public boolean doAdd(String category,String title,String source,String
	 * content,String author) { boolean add = false; DBUtil dbUtil = new DBUtil();
	 * connection = dbUtil.geConnection(); //String sql =
	 * "select password from admin where username = " + username + "'"; String sql =
	 * "insert into courtintroduce(category,title,source,content,author) values(?,?,?,?,?)"
	 * ;
	 * 
	 * try { PreparedStatement statement = connection.prepareStatement(sql);
	 * statement.setString(1, category); statement.setString(2, title);
	 * statement.setString(3, source); statement.setString(4, content);
	 * statement.setString(5, author); System.out.println("结果前" + rs);
	 * System.out.println(add); int i = statement.executeUpdate(); if (i>0) { add =
	 * true; }
	 * 
	 * } catch (SQLException e) { e.printStackTrace(); }finally { if (rs != null) {
	 * try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if
	 * (statement != null) { try { statement.close(); } catch (SQLException e) {
	 * e.printStackTrace(); } } if(connection != null) { try { connection.close(); }
	 * catch (SQLException e) { e.printStackTrace(); } } dbUtil.close(); } return
	 * add;
	 * 
	 * }
	 */
	public boolean doDel(int id) {
		boolean del = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		//String sql = "select password from admin where username = " + username + "'";
		String sql = "delete from courtintroduce where id =?";
		try {
			statement = connection.prepareStatement(sql);
			statement.setInt(1, id);
			int i = statement.executeUpdate();
			if (i>0) {
				del = true;
			}
				
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return del;
		
	}
	
	
	public List<CourtIntroduce> findAllByLbForPX(String lbString) {
		 System.out.println("run findAllByLb " + lbString);
		 List<CourtIntroduce> newlist = new ArrayList<CourtIntroduce>();
		 DBUtil dbUtil = new DBUtil();
		 connection = dbUtil.geConnection();
		 String sql = "select * from courtintroduce where category = ? ";
		 try {
		  statement = connection.prepareStatement(sql);
		  statement.setString(1, lbString);
		  rs = statement.executeQuery();
		  while (rs.next()) {
			  CourtIntroduce courtintroduce = new CourtIntroduce();
			  courtintroduce.setId(rs.getInt("id"));
			  courtintroduce.setTitle(rs.getString("title"));
			  courtintroduce.setContent(rs.getString("content"));
			  courtintroduce.setTime(rs.getDate("time"));
			  courtintroduce.setPicture(rs.getString("picture"));
			  courtintroduce.setAuthor(rs.getString("author"));
			  
			  courtintroduce.setCategory(rs.getString("category"));
		   newlist.add(courtintroduce);
		   System.out.println("findAllByLb  " + courtintroduce);
		  }
		  
		 } catch (Exception e) {
		  e.printStackTrace();
		 }finally {
		  if (rs != null) {
		   try {
		    rs.close();
		   } catch (SQLException e) {
		    e.printStackTrace();
		   }
		  }
		  if (statement != null) {
		   try {
		    statement.close();
		   } catch (SQLException e) {
		    e.printStackTrace();
		   }
		  }
		  if(connection != null) {
		   try {
		    connection.close();
		   } catch (SQLException e) {
		    e.printStackTrace();
		   }
		  }
		  dbUtil.close();
		 }
		 return newlist;
		 
		}

		//查找上一页的ID
		public CourtIntroduce  findPreNewsById(List<CourtIntroduce > listCourtIntroduce , int id) {
			CourtIntroduce courtintroduce = null;
		 for(int i=0;i<listCourtIntroduce .size();i++) {
		  if(id == listCourtIntroduce .get(i).getId()&&i!=0) {
			  courtintroduce = listCourtIntroduce.get(i-1);
		   return courtintroduce;
		  }
		 }
		 return courtintroduce;
		  
		 }


		public CourtIntroduce findNextNewsById(List<CourtIntroduce>  listCourtIntroduce, int id) {
			CourtIntroduce courtintroduce = null;
		 for(int i=0;i<listCourtIntroduce.size();i++) {
		  if(id == listCourtIntroduce.get(i).getId()&&i+1<listCourtIntroduce.size()) {
			  courtintroduce = listCourtIntroduce.get(i+1);
		   return courtintroduce;
		  }
		 }
		 return courtintroduce;
		  
		  
		 }
	
		//后端查询总数
		public int findbackCountByLb(String lbString) {
			DBUtil dbUtil = new DBUtil();
			connection = dbUtil.geConnection();
			int count = 0;
			String sql = "select count(*) totalCount from courtintroduce where category =? ";
			try {
				statement = connection.prepareStatement(sql);
				statement.setString(1, lbString);
				rs = statement.executeQuery();
				if (rs.next()) {
					count=rs.getInt("totalCount");
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return count;
			
		}
		//后端分页
		public List<CourtIntroduce> findbackByLbForFY(String lbString,Page page) {
			List<CourtIntroduce> list = new ArrayList<CourtIntroduce>();
			DBUtil dbUtil = new DBUtil();
			connection = dbUtil.geConnection();
			String sql = "select * from courtIntroduce where category =? order by time desc limit ?,? ";
			try {
				statement = connection.prepareStatement(sql);
				statement.setString(1, lbString);
				statement.setInt(2, page.getBeginIndex());
				statement.setInt(3, page.getEveryPage());
				rs = statement.executeQuery();
				while(rs.next()) {
					CourtIntroduce courtIntroduce = new CourtIntroduce();
					courtIntroduce.setCategory(rs.getString("category"));
					courtIntroduce.setId(rs.getInt("id"));
					courtIntroduce.setTitle(rs.getString("title"));
					courtIntroduce.setContent(rs.getString("content"));
					courtIntroduce.setAuthor(rs.getString("author"));
					courtIntroduce.setSource(rs.getString("source"));
					courtIntroduce.setTime(rs.getDate("time"));
					courtIntroduce.setPicture(rs.getString("picture"));
					courtIntroduce.setPuton(rs.getInt("puton"));
					System.out.println(courtIntroduce.getPicture());
					list.add(courtIntroduce);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return list;
			
		}

		//后端模糊查询后总数
		public int findselectCountByLb(String lbString,String tilString) {
			DBUtil dbUtil = new DBUtil();
			connection = dbUtil.geConnection();
			int count = 0;
			String sql = "select count(*) totalCount from courtIntroduce where category =? and concat(id,title,content,category,author,source,time,puton) like ? ";
			try {
				statement = connection.prepareStatement(sql);
				statement.setString(1, lbString);
				statement.setString(2,"%" + tilString + "%");
				rs = statement.executeQuery();
				if (rs.next()) {
					count=rs.getInt("totalCount");
					System.out.print("totalCount :"+count);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return count;
			
		}

	
	public List<CourtIntroduce> findAll() {
		List<CourtIntroduce> list = new ArrayList<CourtIntroduce>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from courtintroduce";
		try {
			statement = connection.prepareStatement(sql);
			rs = statement.executeQuery();
			while(rs.next()) {
				CourtIntroduce newBean = new CourtIntroduce();
				newBean.setId(rs.getInt("id"));
				newBean.setTitle(rs.getString("title"));
				newBean.setContent(rs.getString("content"));
				newBean.setPicture(rs.getString("picture"));
				newBean.setTime(rs.getDate("time"));
				newBean.setAuthor(rs.getString("author"));
				newBean.setPicturetitle(rs.getString("picturetitle"));
				newBean.setCategory(rs.getString("category"));
				list.add(newBean);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;
		
	}
	
	public CourtIntroduce findOneByLb(String lbString) {
		CourtIntroduce newBean = new CourtIntroduce();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from courtintroduce where category =?and puton=1 ";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			rs = statement.executeQuery();
			while(rs.next()) {
				newBean.setId(rs.getInt("id"));
				newBean.setTitle(rs.getString("title"));
				newBean.setContent(rs.getString("content"));
				newBean.setPicture(rs.getString("picture"));
				newBean.setPicturetitle(rs.getString("picturetitle"));
				newBean.setTime(rs.getDate("time"));
				newBean.setAuthor(rs.getString("author"));
				newBean.setCategory(rs.getString("category"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return newBean;
		
	}
	

	//总页数
	public int findCountByLb(String lbString) {
		List<NewsBean> list = new ArrayList<NewsBean>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		int count = 0;
		String sql = "select count(*) totalCount from courtintroduce where category =?";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			rs = statement.executeQuery();
			if (rs.next()) {
				count=rs.getInt("totalCount");
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return count;
		
	}

	
//分页
public List<NewsBean> findAllByLbForFY(String lbString,Page page) {
	List<NewsBean> list = new ArrayList<NewsBean>();
	DBUtil dbUtil = new DBUtil();
	connection = dbUtil.geConnection();
	String sql = "select * from courtintroduce where category =? limit ?,?";
	try {
		statement = connection.prepareStatement(sql);
		statement.setString(1, lbString);
		statement.setInt(2, page.getBeginIndex());
		statement.setInt(3, page.getEveryPage());
		rs = statement.executeQuery();
		while(rs.next()) {
			NewsBean newBean = new NewsBean();
			newBean.setCategory(rs.getString("category"));
			newBean.setId(rs.getInt("id"));
			newBean.setTitle(rs.getString("title"));
		    newBean.setContent(rs.getString("content"));
			newBean.setAuthor(rs.getString("author"));
			newBean.setSource(rs.getString("source"));
			newBean.setTime(rs.getDate("time"));
			newBean.setPicture(rs.getString("picture"));
			System.out.println(newBean.getPicture());
			list.add(newBean);
		}
		
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		dbUtil.close();
	}
	return list;
	
}
	
	
	//查找类别
		public List<CourtIntroduce> findAllByLb(String lbString) {
			System.out.println("run findAllByLb " + lbString);
			List<CourtIntroduce> list = new ArrayList<CourtIntroduce>();
			DBUtil dbUtil = new DBUtil();
			connection = dbUtil.geConnection();
			String sql = "select * from courtintroduce where category = ?and puton=1 ";
			try {
				statement = connection.prepareStatement(sql);
				statement.setString(1, lbString);
				rs = statement.executeQuery();
				while (rs.next()) {
					CourtIntroduce newBean = new CourtIntroduce();
					newBean.setId(rs.getInt("id"));
					newBean.setTitle(rs.getString("title"));
					newBean.setContent(rs.getString("content"));
					newBean.setTime(rs.getDate("time"));
					newBean.setPicture(rs.getString("picture"));
					newBean.setHomepage(rs.getInt("homepage"));
					newBean.setAuthor(rs.getString("author"));
					newBean.setCategory(rs.getString("category"));
					list.add(newBean);
					System.out.println("findAllByLb  " + newBean);
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return list;
			
		}
	
public CourtIntroduce findNewsById(int id) {
		
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		CourtIntroduce newsbean = new CourtIntroduce();
		String sql = "select * from courtintroduce where id = ?";
		try {
			statement = connection.prepareStatement(sql);
			statement.setInt(1, id);
			rs = statement.executeQuery();
			
			if(rs.next()) {
				newsbean.setId(rs.getInt("id"));
				newsbean.setTitle(rs.getString("title"));
				newsbean.setContent(rs.getString("content"));
				newsbean.setPicture(rs.getString("picture"));
				newsbean.setTime(rs.getDate("time"));
				newsbean.setAuthor(rs.getString("author"));
				newsbean.setCategory(rs.getString("category"));
				newsbean.setPuton(rs.getInt("puton"));
				
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
	
		return newsbean;
		
	}
public List<CourtIntroduce> findAllByProForFY(String tilString,Page page) {
	List<CourtIntroduce> list = new ArrayList<CourtIntroduce>();
	DBUtil dbUtil = new DBUtil();
	connection = dbUtil.geConnection();
	String sql = "select * from court where concat(id,title,content,category,author,time,picture) like ? limit ?,?";
	try {
		 statement = connection.prepareStatement(sql);
		   statement.setString(1,"%" + tilString + "%");
		statement.setInt(2, page.getBeginIndex());
		statement.setInt(3, page.getEveryPage());
		rs = statement.executeQuery();
		while(rs.next()) {
			CourtIntroduce newsBean = new CourtIntroduce();
			newsBean.setCategory(rs.getString("category"));
			newsBean.setId(rs.getInt("id"));
			newsBean.setTitle(rs.getString("title"));
			newsBean.setContent(rs.getString("content"));
			newsBean.setAuthor(rs.getString("author"));
			newsBean.setTime(rs.getDate("time"));
			newsBean.setPicture(rs.getString("picture"));
			System.out.println(newsBean.getPicture());
			list.add(newsBean);
		}
		
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if (statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		dbUtil.close();
	}
	return list;
	
}

	public CourtIntroduce findById(int id) {
		
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		CourtIntroduce newBean = new CourtIntroduce();
		String sql = "select * from courtintroduce where id = ?";
		try {
			statement = connection.prepareStatement(sql);
			statement.setInt(1, id);
			rs = statement.executeQuery();
			
			while(rs.next()) {
				newBean.setTitle(rs.getString("title"));
				newBean.setContent(rs.getString("content"));
				newBean.setTime(rs.getDate("time"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
	
		return newBean;
	}
	
	
	
	
	
	@Override
	public String toString() {
		return "CourtIntroduce [id=" + id + ", category=" + category + ", title=" + title + ", content=" + content
				+ ", homepage=" + homepage + ", author=" + author + ", time=" + time + ", picturetitle="
				+ picturetitle + ", source=" + source + ",]";
	}
	
	public static void main(String[] args) {
		System.out.println("我运行了");
		CourtIntroduce ci = new CourtIntroduce();
		String category = "wlw";
		String title = "信息工程";
		String content = "物联网";
		int homepage = 19;
		//ci.doAdd(category, title, content, homepage);
	}
	
	
}